package ModelLayer;

import java.util.*;

public class OrderContainer{
    private ArrayList<Order> orderContainer;
    private static OrderContainer instance;

    private OrderContainer(){
        orderContainer = new ArrayList<Order>();
    }

    public static OrderContainer getInstance(){
        if(instance == null)
            instance = new OrderContainer();
        return instance;
    }

    public void addOrder(Order order){
        orderContainer.add(order);
    }

    public Order findOrderById(int id){
        Order sObject = null;
        int index = 0;
        boolean found = false;
        while(index < orderContainer.size() && !found)
        {
            sObject = orderContainer.get(index); 
            if(sObject.getId()== id)
            {
                found = true;
            }
            else{
                index++;
            }
        }
        if(found){
            return orderContainer.get(index) ;
        }else{
            return  null;
        }
    }
    
    public ArrayList<Order> getOrderList()
    {
        return orderContainer;
    }

    public void deleteOrder(Order p){
        if(orderContainer.contains(p))
            orderContainer.remove(p);
    }
}